<template>
  <div class="vueBox">
      <div class="marquee">
        <div class="marquee_box">
          <ul class="marquee_list" :class="{marquee_top:animate}">
            <li
              v-for="(item, index) in marqueeList"
              :key="index"
              :style="{background: item.background, display: 'flex', 'justify-content': 'space-between',  'align-items': 'center'}"
            >
              <span>{{item.name}}</span>
              <span>在</span>
              <span class="red"> {{item.city}}</span>
              <span>杀敌</span>
              <span class="red"> {{item.amount}}</span>
              <span>万</span>
            </li>
          </ul>
        </div>
      </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            animate: false,
            marqueeList:[]
        }
    },
    created() {
        setInterval(this.showMarquee, 2000);
    },
    mounted() {
        this.marqueeList = this.$window.scrollData
    },
    methods: {
         showMarquee: function() {
            this.animate = true;
            setTimeout(() => {
              if (this.marqueeList.length % 2 != 0) {
                this.marqueeList[0]["background"] =
                  this.marqueeList[0]["background"] === "rgba(0,0,0,.4)"
                    ? "rgba(0,0,0,.6)"
                    : "rgba(0,0,0,.4)";
              }
              this.marqueeList.push(this.marqueeList[0]);
              this.marqueeList.shift();
              this.animate = false;
            }, 500);
          }
    },
}
</script>

<style>
    div,
      ul,
      li,
      span,
      img {
        margin: 0;
        padding: 0;
        display: flex;
        box-sizing: border-box;
      }

      .marquee {
        width: 100%;
        height: 308px;
        color: #3a3a3a;
        box-sizing: border-box;
      }

      .marquee_box {
        display: block;
        position: relative;
        width: 60%;
        /* 占四分之三的高度  */
        height: 86%;
        overflow: hidden;
      }

      .marquee_list {
        display: block;
        width: 100%;
        position: absolute;
        top: 0;
        left: 0;
      }

      .marquee_top {
        transition: all 0.5s ease-out;
        margin-top: -44px;
      }

      .marquee_list li {
        height: 44px;
        line-height: 30px;
        font-size: 14px;
        padding-left: 20px;
      }

      .marquee_list li span {
        padding: 0 2px;
      }

      .red {
        color: #ff0101;
      }
</style>